import { defineStore } from 'pinia'
import { ref } from 'vue'
export const usePlayList = defineStore(
  'playlist',
  () => {
    const playlist = ref([])
    const updatePlaylist = newPlaylist => {
      playlist.value = newPlaylist
    }
    const removePlaylist = () => {
      playlist.value = []
    }
    return {
      playlist,
      updatePlaylist,
      removePlaylist
    }
  },
  {
    persist: {
      enabled: true,
      //持久化到localStorage
      strategies: [
        {
          storage: window.localStorage,
          key: 'playlist'
        }
      ]
    }
  }
)


export const usePlayListDetail = defineStore(
  'playlistDetail',
  () => {
    const playlistDetail = ref({})

    const updatePlaylistDetail = newPlaylistDetail => {
      playlistDetail.value = newPlaylistDetail
    }

    const removePlaylistDetail = () => {
      playlistDetail.value = {}
    }
    return {
      playlistDetail,
      updatePlaylistDetail,
      removePlaylistDetail
    }
  },
  {
    persist: {
      enabled: true,
      //持久化到localStorage
      strategies: [
        {
          storage: window.localStorage,
          key: 'playlistDetail'
        }
      ]
    }
  }
)

export const usePlayIndex = defineStore(
  'playIndex',
  () => {
    const playIndex = ref(0)
    const playMode = ref(0)
    const updatePlayIndex = newPlayIndex => {
      playIndex.value = newPlayIndex
    }

    const removePlayIndex = () => {
      playIndex.value = 0
    }
    return {
      playMode,
      playIndex,
      updatePlayIndex,
      removePlayIndex
    }
  },
  {
    persist: {
      enabled: true,
      //持久化到localStorage
      strategies: [
        {
          storage: window.localStorage,
          key: 'playIndex'
        }
      ]
    }
  }
)


//播放状态
export const usePlayStatus = defineStore(
  'playStatus',
  () => {
    const playStatus = ref(false)

    const updatePlayStatus = newPlayStatus => {
      playStatus.value = newPlayStatus
    }

    const removePlayStatus = () => {
      playStatus.value = false
    }
    return {
      playStatus,
      updatePlayStatus,
      removePlayStatus
    }
  },
  {
    persist: {
      enabled: true,
      //持久化到localStorage
      strategies: [
        {
          storage: window.localStorage,
          key: 'playStatus'
        }
      ]
    }
  }
)

//播放信息
export const usePlayE = defineStore(
  'playE',
  () => {
    const playE = ref({})

    const updatePlayE = newPlayE => {
      playE.value = newPlayE
    }

    const removePlayE = () => {
      playE.value = {}
    }
    return {
      playE,

      updatePlayE,
      removePlayE
    }
  },
  {
    persist: {
      enabled: true,
      //持久化到localStorage
      strategies: [
        {
          storage: window.localStorage,
          key: 'playE'
        }
      ]
    }
  }
)